<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends SCAction {
    public function index(){		
        $this->display(C('Installer_setup_n'));
    }
	public function setdatabase(){
	 $config=C();
	 $config['Installer_setup_n']='setup2';
	// $config['']='';
	$errstr="";
	$config['DB_TYPE']='mysql';
	if ($_POST['db_host']!="") $config['DB_HOST']=$_POST['db_host'];
	if ($_POST['db_name']!=""){
	$config['DB_NAME']=$_POST['db_name'];
	}else{
	$errstr="数据库名称不能为空<br>";
	};
	
	if ($_POST['db_user']!=""){
	$config['DB_USER']=$_POST['db_user'];
	}else{
	$errstr.="用户名称不能为空<br>";
	};
	if ($_POST['db_pwd']!=""){
	$config['DB_PWD']=$_POST['db_pwd'];
	}else{
	$errstr.="密码不能为空<br>";
	};
	if ($_POST['db_port']!="")$config['DB_PORT']=$_POST['db_port'];
	if ($_POST['db_prefix']!=""){
	$config['DB_PREFIX']=$_POST['db_prefix'];
	}else{
	$errstr.="表前缀不能为空<br>";
	};
     if ($errstr!="" ){
	    $this->error($errstr);
	 }
	 else
	 {
	 //判断数据库可用性未写代码。
     C($config);
	 $Data = M(); 
       if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'index` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` tinytext NOT NULL,
  `alink` tinytext NOT NULL,
  `ordi` int(11) NOT NULL DEFAULT "0",
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'index表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'index表完成</br>';
			};
       if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pid` int(11) NOT NULL DEFAULT "0",
  `title` tinytext NOT NULL,
  `info` text NOT NULL,
  `datetime` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'info表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'info表完成</br>';
			};
	   if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'info_index` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` tinytext NOT NULL,
  `type` smallint(6) NOT NULL DEFAULT "1",
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'info_index表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'info_index表完成</br>';
			};
	   if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'menu` (
  `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,
  `pid` smallint(4) unsigned NOT NULL,
  `cname` varchar(50) NOT NULL DEFAULT "",
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'menu表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'menu表完成</br>';
			};
	   if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pid` int(11) NOT NULL DEFAULT "0",
  `title` tinytext NOT NULL,
  `img` tinytext NOT NULL,
  `info` text NOT NULL,
  `datetime` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'products表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'products表完成</br>';
			};
	   if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'products_index` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` tinytext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'products_index表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'products_index表完成</br>';
			};
	   if($Data->execute('
CREATE TABLE IF NOT EXISTS `'.$config['DB_PREFIX'].'users` (
  `username` varchar(60) NOT NULL,
  `password` varchar(64) NOT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

             ')===false){
			  $info.='<br>创建'.$config['DB_PREFIX'].'users表失败</br>';
			  $this->error($info);
			}else{
			  $info.='<br>创建'.$config['DB_PREFIX'].'users表完成</br>';
			};
		C($config,'BY_USER_SET_CONFIG');
	    $this->success($info.'数据库设置成功！', 'setup2');
	 };
	}
	public function setup2(){
	
	  $this->display();
	}
	public function setadmin(){

	 if($this->D_add('Users','setup3','管理账号设置成功！')){
		 $config=C();
		 $config['Installer_setup_n']='setup3';	 
	     C($config,'BY_USER_SET_CONFIG');
	 }
	}
	public function setup3(){
	
	  $this->display();
	}
}